//
//  IfengButton+Create.m
//  IfengNews
//
//  Created by tianhy on 13-5-14.
//
//

#import "UIButton+Create.h"
#import "CLGloble.h"
#import "UIView+Utils.h"

@implementation UIButton(Create)
+ (UIButton *)buttonWithImage:(UIImage *)image
            withSelectedImage:(UIImage *)selectedImage
                        title:(NSString *)title
                    withFrame:(CGRect)rect
          withImageEdgeInsets:(UIEdgeInsets)edgeInsets
                withTitleRect:(CGRect)titleRect
                withTitleFont:(UIFont *)font
               withTitleColor:(UIColor *)color
{
  UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  button.frame = rect;
  [button setImage:image forState:UIControlStateNormal];
  if(selectedImage)
    [button setImage:selectedImage forState:UIControlStateHighlighted];
  [button setImageEdgeInsets:edgeInsets];
  
  UILabel *titleLabel = [[UILabel alloc] init];
  if(titleRect.size.height==0 || titleRect.size.width==0)
    titleRect = button.bounds;
  titleLabel.frame = titleRect;
  titleLabel.font = font;
  [titleLabel setTextColor:color];
  titleLabel.backgroundColor = [UIColor clearColor];
  titleLabel.text = title;
  [button addSubview:titleLabel];
  
  return button;
}

@end
